<template>
  <div class="alertitem">
    <!-- Dom内容 -->
    <p>请填写课程相关信息</p>
    <div class="msglist">
      <div class="left">课程名称</div>
      <div class="right">
        <el-input v-model="classTitle" placeholder="请输入内容"></el-input>
      </div>
    </div>

    <div class="msglist">
      <div class="left">课程封面</div>
      <div class="right">
        <img :src="classImg" alt="" />
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程状态</div>
      <div class="right">
        <el-switch v-model="statebar" active-text="上架" inactive-text="下架">
        </el-switch>
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程分类</div>
      <div class="right">
        <span>{{ this.jiNeng }}</span>
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程简介</div>
      <div class="right">
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="introduce"
        >
        </el-input>
      </div>
    </div>
    <div class="bottombtn">
      <el-button @click="subscribe" type="success">修改</el-button>
      <el-button @click="openset">取消</el-button>
    </div>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
export default {
  name: "",
  props: ["item"],
  data() {
    return {
      Peoplebuy: "",
      cid: "",
      classBanner: [],
      classImg: "",
      classPrice: "",
      classTitle: "",
      collect: 0,
      introduce: "",
      jiNeng: "",
      num: 0,
      personnum: 0,
      seePeople: "",
      shopping: "",
      statebar: 1,
      zhifu: 0,
      zhifuState: 0,
    };
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {
  
  },
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
      this.getdata();
  },
  // Vue方法定义
  methods: {
    
    async getdata() {
      let {cid,id} = this.item
       let data = await this.$axios.get("/api/answer/curriculum").then((res) => {
        return res.data;
      });
     
      let index = data.findIndex((item)=>{
        return item.id ===Number(id)
      })
      console.log(index);
      if(index!== -1){
        JSON.parse(data[index].teacherClassList).forEach(item=>{ 
          console.log(item.cid,cid);
          if(Number(item.cid)===Number(cid)){
            console.log(item);
            for(let key in item){
              this[key] = item[key]
            }
          }
        })
      }
    },
    // 点击取消
    openset() {
      this.$emit("setflag", false);
    },
    // 点击确定
    subscribe() {
      let obj = {
        Peoplebuy: this.Peoplebuy,
        cid: this.cid,
        classBanner: this.classBanner,
        classImg:this.classImg,
        classPrice:this.classPrice,
        classTitle:this.classTitle,
        collect: this.collect,
        introduce: this.introduce,
        jiNeng: this.jiNeng,
        num: this.num,
        personnum:this.personnum,
        seePeople: this.seePeople,
        shopping: this.shopping,
        statebar: this.statebar,
        zhifu: this.zhifu,
        zhifuState:this.zhifuState,
      }
      this.$axios.post("/api/answer/setTeacherClassItem", {...this.item,obj });
      this.$emit("setflag", false,true);
    },
  },
};
</script>

<style scoped>
/* @import url(''); 引入css类 */
.alertitem {
  width: 650px;
  height: 540px;
  padding: 20px;
  background: white;
  opacity: 1;
  z-index: 9999;
  border-radius: 15px;
}
.opensetbtn {
  position: absolute;
  right: 44px;
  top: 78px;
  height: 30px;
  line-height: 5px;
}

/*  */
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.left {
  float: left;
  width: 100px;
}
.right {
  float: left;
  width: 50%;
}
.msglist {
  overflow: hidden;
  padding: 10px 10px;
}
.bottombtn {
  padding-left: 100px;
}
.bottombtn > button {
  margin-right: 25px;
}
</style>